package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.OrderItemDao;
import com.tequila.core.service.OrderItemService;
import com.tequila.domain.dto.OrderItemDto;
import com.tequila.domain.entity.OrderItem;
import com.tequila.domain.query.OrderItemQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemService {
    public static final Logger logger = LoggerFactory.getLogger(OrderItemServiceImpl.class);

    @Resource
    private OrderItemDao orderItemDao;

    @Override
    public Pagination<OrderItemDto> queryPageListByParam(OrderItemQuery query) {
        Assert.assertNotNull(query);
        int total = orderItemDao.queryPageCountByParam(query);

        List<OrderItemDto> list = Lists.newArrayList();
        if (total > 0) {
            list = orderItemDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public OrderItemDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        OrderItem orderItem = orderItemDao.queryById(id);
        OrderItemDto orderItemDto = new OrderItemDto();
        BeanHelper.copyProperties(orderItemDto,orderItem);
        return orderItemDto;
    }

    @Override
    public List<OrderItemDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return orderItemDao.queryByIdList(idList);
    }

    @Override
    public List<OrderItemDto> queryListByParam(OrderItemQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return orderItemDao.queryListByParam(query);
    }


    @Override
    public Long insert(OrderItem entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        orderItemDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(OrderItem entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        orderItemDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(OrderItem param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return orderItemDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(OrderItem param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return orderItemDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return orderItemDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return orderItemDao.deleteByIdList(idList);
    }
}
